﻿<!-- Views/Admin/CreateOption.cshtml -->
@model WebApplication1.Models.Option

@{
    ViewBag.Title = "添加选项";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="container">
    <h2>添加选项</h2>
    <h4>@ViewBag.QuestionText</h4>
    <hr />

    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()

        @Html.HiddenFor(model => model.QuestionId)

        <div class="form-horizontal">
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })

            <div class="form-group">
                @Html.LabelFor(model => model.OptionLabel, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.OptionLabel, new { htmlAttributes = new { @class = "form-control", placeholder = "例如: A, B, C, D 或 True, False" } })
                    @Html.ValidationMessageFor(model => model.OptionLabel, "", new { @class = "text-danger" })
                    <span class="help-block">选项标识，如 A、B、C、D 或 True、False</span>
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.OptionText, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.TextAreaFor(model => model.OptionText, new { @class = "form-control", rows = 3, placeholder = "请输入选项内容" })
                    @Html.ValidationMessageFor(model => model.OptionText, "", new { @class = "text-danger" })
                </div>
            </div>
            <br />
            <div class="form-group">
                <div class="col-md-offset-2 col-md-10">
                    <input type="submit" value="添加选项" class="btn btn-primary" />
                    <a href="@Url.Action("Options", "Admin", new { questionId = Model.QuestionId })" class="btn btn-danger">返回列表</a>
                </div>
            </div>
        </div>
    }
</div>

@section Scripts {

    <script>
        $(document).ready(function() {
            // 表单提交前验证
            $('form').submit(function() {
                var optionLabel = $('#OptionLabel').val();
                var optionText = $('#OptionText').val();

                if (!optionLabel.trim()) {
                    alert('请输入选项标识');
                    return false;
                }

                if (!optionText.trim()) {
                    alert('请输入选项内容');
                    return false;
                }

                return true;
            });
        });
    </script>
}